<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>值班内容</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <!--本体列表，数据 -->
        <div class="table-body">
          <div class="table-body-box">
            <el-table
                ref="multipleTable"
                :data="arryList"
                border
                :height="tableHeight"
                tooltip-effect="dark"
                style="width: 100%"
                header-cell-class-name="table-text-c"
                cell-class-name="table-text-c">
              <el-table-column
                  prop="id"
                  label="ID">
              </el-table-column>
              <el-table-column
                  prop="name"
                  label="值班内容">
              </el-table-column>
              <el-table-column
                  label="上级类目">
                <template slot-scope="scope">
                  {{ scope.row.parent_id ? '' : '主类目' }}
                </template>
              </el-table-column>
              <el-table-column
                  label="操作"
                  width="200"
                  :key="9"
              >
                <template slot-scope="scope">
                  <el-button plain type="primary" size="mini" @click="dutyId=scope.row.id,addvisible=true">编辑
                  </el-button>
                  <el-button plain type="danger" @click="handleDetel(scope.row.id)" size="mini">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <!--工具条 分页-->
        <el-col :span="24" class="toolbar">
          <el-pagination
              background
              :page-size="page.pagesize"
              :current-page="page.pageindex"
              layout="total, prev, pager, next"
              :total="page.total"
              @current-change="handleSizeChange"></el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">返回</el-button>
        <el-button @click="dutyId=0,addvisible=true" size="small" type="primary" plain>添加值班项</el-button>
      </div>
    </div>
    <patrol :visible.sync="addvisible" :dutyId="dutyId" @InitFn="InitFn"></patrol>
  </div>
</template>

<script>
import {pagination} from '@/utils/util.js'
import {dutyOptionIndex, dutyOptionDelete} from "@/api/admin/duty"

import patrol from './patrol'

export default {
  props: ['visible'], // listType 1 签收 2 未签收
  components: {patrol},
  data() {
    return {
      addvisible: false,
      dutyId: 0,
      healthId: 0,
      dialogVisible: false,
      arryList: [], // 数据列表
      // 页数
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      tableHeight: 0
    }
  },
  watch: {
    visible() {
      if (this.visible) {
        let n = this;
        this.$nextTick(() => {
          let height = n.$refs.dialogBox.offsetHeight;  //top 50 1 search 50 page 50 10 footer 50 1
          this.tableHeight = height - (51 + 20 + 50 + 51)
        })
        this.InitFn('load')
      } else {
        this.arryList = [];
        this.page.pageindex = 1
        this.page.total = 0
      }
      this.dialogVisible = this.visible
    }
  },
  created() {
  },
  methods: {
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    // 初始化
    async InitFn(option_) {
      let option = {}
      option.p = this.page.pageindex
      dutyOptionIndex(option).then(res => {
        if (!res.code) {
          this.arryList = res.list.data
          this.page.total = res.list.total
          if (option_ !== 'load') {
            this.$emit('InitFn')
          }
        }
      })
    },
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    handleDetel(id) {
      this.$confirm('确认删除该值班内容,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        dutyOptionDelete({id: id}).then(res => {
          if (!res.code) {
            this.$message.success(res.msg)
            this.InitFn()
          } else {
            this.$message.error(res.msg)
          }
        })
      }).catch(() => {
      })
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 60%;
  height: 70%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.toolbarLine {
  text-align: center;
}

.hearder-search {
  display: flex;
  align-items: center;
}

.breadcrumb-container {
  margin-bottom: 10px;
}

.parentsList p {
  background: #f8f8f8;
  margin-bottom: 5px;
}

.parentsList p:last-child {
  margin-bottom: 0;
}
</style>


